#include <iostream>
using namespace std;
int n, k, numbers[10] = { 2,4,6,8,0,1,3,5,7,9 };
void QS(int Hindex, int Tindex)
{
	int middle = Hindex;
	int Mnum = numbers[middle];
	int i = Hindex + 1, j = Tindex;
	while (i <= j)
	{
		for (; j >= Hindex; j--)
		{

			if (numbers[j] <= Mnum)    break;
		}

		//while(numbers[i]<Mnum)i++;
		//while(numbers[j]>Mnum)j--;
		for (int i = 0; i < 10; i++)cout << numbers[i] << " "; cout << endl;
		cout << "j=" << j << endl;
		swap(numbers[j--], numbers[middle]);
		for (int i = 0; i < 10; i++)cout << numbers[i] << " "; cout << endl << endl;

		Mnum = numbers[middle];
		for (; i <= Tindex; i++)
		{
			if (numbers[i] >= Mnum)    break;
		}
		for (int i = 0; i < 10; i++)cout << numbers[i] << " "; cout << endl;
		cout << "i=" << i << endl;
		swap(numbers[middle], numbers[i++]);
		for (int i = 0; i < 10; i++)cout << numbers[i] << " "; cout << endl << endl;

	}

	int dscds;
	cin >> dscds;

	if (j > Hindex)
	{
		cout << "QS1";
		QS(Hindex, j);
	}
	if (i < Tindex)
	{
		cout << "OS2";
		QS(i, Tindex);
	}
}
int main()
{
	n = 10;
	QS(0, n - 1);
	//cin>>k;
	for (int i = 0; i < 10; i++)cout << numbers[i] << " "; cout << endl;
	return 0;
}